package demo.dcs.util;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by floyd on 16/2/2.
 */
public class StringSplitter {

    private StringSplitter() {
        throw new IllegalStateException("Utility class");
    }

    public static List<String> split(String msg, int maxMsgLength) {
        List<String> sentMsgList = new ArrayList<String>();
        if (msg == null || msg.isEmpty()) {
            return sentMsgList;
        }
        int startPoint = 0;
        do {
            if (msg.length() >= startPoint + maxMsgLength) {
                sentMsgList.add(msg.substring(startPoint, startPoint + maxMsgLength));
            } else {
                sentMsgList.add(msg.substring(startPoint));
            }
            startPoint += maxMsgLength;
        } while (msg.length() > startPoint);
        return sentMsgList;
    }
}
